<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>main</title>
		<!-- css代码 start -->
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/icons-extra.css" rel="stylesheet" />
		<link href="css/global.css" rel="stylesheet" />
		<style>
			.mui-bar-tab .mui-tab-item .mui-icon-extra {
				top: 3px;
				width: 23px;
				height: 23px;
				padding-top: 0;
				padding-bottom: 0;
			}

			.mui-bar .mui-icon-extra {
				font-size: 24px;
				position: relative;
				z-index: 20;
				padding-top: 10px;
				padding-bottom: 10px;
			}
				
			.mui-bar-tab .mui-tab-item .mui-icon-extra~.mui-tab-label {
				font-size: 11px;
				display: block;
				overflow: hidden;
				text-overflow: ellipsis;
			}

		</style>
		<!-- css代码 end -->
	</head>
	<body>

		<!-- html代码 start -->
		<!-- <header class="mui-bar mui-bar-nav">
			<h1 id="title" class="mui-title">首页</h1>
		</header> -->
		<nav class="mui-bar mui-bar-tab" id="nav-bar" style="background: #fff;">
			<a id="defaultTab" class="mui-tab-item mui-active" href="view/main/indexTL.html">
				<img src="images/icon_381.png" style="width: 24px;margin: 8px auto 0;">
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" href="view/main/workbench.html">
				<span class="mui-icon-extra mui-icon-extra-class"></span>
				<span class="mui-tab-label">工作台</span>
			</a>
			<a class="mui-tab-item" href="view/main/mine.html">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<!-- html代码 end -->

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="js/mui.min.js"></script>
		<script src="js/utils/h.js"></script>
		<script src="js/constant.js"></script>
		<script src="js/common.js"></script>
		<script src="js/utils/base64.js"></script>
		<script src="js/utils/md5.js"></script>
		<script src="js/utils/sortMap.js"></script>
		<script src="js/utils/http.js"></script>
		<script src="js/app.js"></script>
		<!-- 基础js end -->
		<script src="js/utils/jpush.js"></script>
		<script src="js/JPushTools.js"></script>
		<script type="text/javascript" charset="utf-8">
			(function($, doc) {
				
				$.init();

				// window.addEventListener('show', function() {
				// 	console.log("main.html 显示成功...");
				// }, false);
				
				var subpages;
				//当前激活选项
				var activeTab;
				var aniShow = {};

				// 创建子页面，首个选项卡页面显示，其它均隐藏；
				$.plusReady(function() {
					var position = app.getUser().position;
					if (position === "Team Leader") {
						subpages = ['view/main/indexTL.html', 'view/main/workbench.html', 'view/main/mine.html'];
						var navBarHtml = `
							<a id="defaultTab" class="mui-tab-item mui-active" href="view/main/indexTL.html">
								<img src="images/icon_381.png" style="width: 24px;margin: 8px auto 0;">
								<span class="mui-tab-label">首页</span>
							</a>
							<a class="mui-tab-item" href="view/main/workbench.html">
								<img src="images/icon_382.png" style="width: 24px;margin: 8px auto 0;">
								<span class="mui-tab-label">工作台</span>
							</a>
							<a class="mui-tab-item" href="view/main/mine.html">
								<img src="images/icon_383.png" style="width: 24px;margin: 8px auto 0;">
								<span class="mui-tab-label">我的</span>
							</a>
						`;
						h("#nav-bar").html(navBarHtml)
					} else {
						subpages = ['view/main/indexFSE.html', 'view/main/workbench.html', 'view/main/mine.html'];
						var navBarHtml = `
							<a id="defaultTab" class="mui-tab-item mui-active" href="view/main/indexFSE.html">
								<img src="images/icon_381.png" style="width: 24px;margin: 8px auto 0;">
								<span class="mui-tab-label">首页</span>
							</a>
							<a class="mui-tab-item" href="view/main/workbench.html">
								<img src="images/icon_382.png" style="width: 24px;margin: 8px auto 0;">
								<span class="mui-tab-label">工作台</span>
							</a>
							<a class="mui-tab-item" href="view/main/mine.html">
								<img src="images/icon_383.png" style="width: 24px;margin: 8px auto 0;">
								<span class="mui-tab-label">我的</span>
							</a>
						`;
						h("#nav-bar").html(navBarHtml)
					}
					activeTab = subpages[0]
					
					var subpage_style = {
						top: '0px',
						bottom: '51px'
					};

					//设置bottom绝对位置  
					//iphoneX中出现遮挡底部tab现象,采用js判断屏幕大小方式改变bottom值  
					//isIPhoneX() 要在plusReady后调用  
					if (isIPhoneX()) {
						subpage_style = {
							top: '0px',
							bottom: '51px', //34px  
							styles: {
								"render": "always",
							}
						};
					}

					var self = plus.webview.currentWebview();
					for (var i = 0; i < 3; i++) {
						var temp = {};
						var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
						if (i > 0) {
							sub.hide();
						} else {
							temp[subpages[i]] = "true";
							mui.extend(aniShow, temp);
						}
						self.append(sub);
					}
					
					startUpdatingLocation()
					
					getRegistrationID();					
					// 获取是否通过通知消息启动
					getLaunchAppCacheNotification();
				});

				
				
				//选项卡点击事件
				$('.mui-bar-tab').on('tap', 'a', function(e) {
					var targetTab = this.getAttribute('href');
					if (targetTab == activeTab) {
						return;
					}
					//显示目标选项卡
					//若为iOS平台或非首次显示，则直接显示
					if (mui.os.ios || aniShow[targetTab]) {
						plus.webview.show(targetTab);
					} else {
						//否则，使用fade-in动画，且保存变量
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						plus.webview.show(targetTab, "fade-in", 300);
					}
					//隐藏当前;
					plus.webview.hide(activeTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
					if (activeTab === 'view/main/indexTL.html'){
						var indexTl=plus.webview.getWebviewById('view/main/indexTL.html');
						if(indexTl){
							indexTl.evalJS('getMyTeamCount()')
						}
					}
				});

				// 自定义事件，模拟点击“首页选项卡”
				document.addEventListener('gohome', function() {
					var defaultTab = document.getElementById("defaultTab");
					//模拟首页点击
					mui.trigger(defaultTab, 'tap');
					//切换选项卡高亮
					var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
					if (defaultTab !== current) {
						current.classList.remove('mui-active');
						defaultTab.classList.add('mui-active');
					}
				});
				
				// 加载是否是通过APPt通知消息启动
				setTimeout(getLaunchAppCacheNotification, 1000);

				$.oldBack = mui.back;
				var backButtonPress = 0;
				$.back = function(event) {
					backButtonPress++;
					if (backButtonPress > 1) {
						plus.runtime.quit();
					} else {
						plus.nativeUI.toast('再按一次退出应用');
					}
					setTimeout(function() {
						backButtonPress = 0;
					}, 1000);
					return false;
				};

			}(mui, document));

			/**  
			 * 判断是否为iPhone X 系列机型  
			 */
			function isIPhoneX() {
				if (plus.device.model.indexOf('iPhone') > -1 && screen.height >= 812) {
					return true;
				} else {
					return false;
				}
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
